package top.fengleifeng.question;

import java.util.Objects;

/**
 * @author : fengelfeing
 * @version V1.0
 * @Project: leetcode-test
 * @Package : top.fengleifeng.question
 * @Description:
 * @Date: 2020年11月16日2:47 下午
 */
public class Z字符串轮转 {

    class Solution {

        public boolean isFlipedString(String s1, String s2) {
            if (s1.length() != s2.length()) {
                return false;
            }
            if (s1.length() == 0) {
                return true;
            }
            char[] charOneArr = s1.toCharArray();
            char[] charTwoArr = s2.toCharArray();
            for (int i = 0; i < charTwoArr.length; i++) {
                if (charOneArr[0] == charTwoArr[i]) {
                    if (check(0, i, charOneArr, charTwoArr)) {
                        return true;
                    }
                }
            }
            return false;
        }

        private boolean check(int s1Start, int s2Start, char[] charOneArr, char[] charTwoArr) {
            for (int i = 0; i < charOneArr.length; i++) {
                if (charOneArr[i] == charTwoArr[s2Start]) {
                    s2Start++;
                    if (s2Start >= charTwoArr.length) {
                        s2Start = 0;
                    }
                } else {
                    return false;
                }
            }
            return true;
        }
    }

    public static void main(String[] args) {
        String s = "waterbottle";
        String s2 = "erbottlewat";
        boolean flipedString = new Z字符串轮转().new Solution().isFlipedString(s, s2);
        System.out.println(flipedString);
    }

}
